import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { ArenaCrossGroupMyServer } from "../cellRenderer/ArenaCrossGroupMyServer";
import { ArenaCrossGroupCellRenderer2 } from "../cellRenderer/ArenaCrossGroupCellRenderer2";
import { ArenaCrossGroupMatchPanel } from "./ArenaCrossGroupMatchPanel";
import { Cache } from "../../../cache/Cache";
import { ArenaCrossGroupIdData } from "../arenaCrossData/ArenaCrossGroupIdData";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GameManager } from "../../../manager/GameManager";
import { ArenaCrossMyBattlesWindow } from "../ArenaCrossMyBattlesWindow";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { SArenaCrossToplists } from "../../../../../Message/Public/SArenaCrossToplists";
import { SArenaCrossGroupBattles } from "../../../../../Message/Public/SArenaCrossGroupBattles";
import { SArenaCrossBattleRecords } from "../../../../../Message/Public/SArenaCrossBattleRecords";
import { SArenaCrossGroupBattleEnd } from "../../../../../Message/Public/SArenaCrossGroupBattleEnd";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class ArenaCrossGroupMatchBattleWindow
    
    export  class ArenaCrossGroupMatchBattleWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            setSize(838, 555);
            titleHeight = 26;
            title = Language.getString(44280);
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStage);
            return;
        }

        /* internal  */onAddToStage(arg1: Object /* flash.events.Event */): void
        {
            this._myBattle.visible = false;
            this._battleRule.x = 66;
            this._battlePrize.x = 161;
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc2=0;
            super.createChildren();
            ObjCreate.createBg(18, 38, 255, 505, this);
            this._myServer = new ArenaCrossGroupMyServer();
            this._myServer.x = 91;
            this._myServer.y = 47;
            this._myServer.selected = true;
            this.addChild(this._myServer);
            this._tileListGroup = ObjCreate.createTileList(27, 89, 240, 410, this);
            this._tileListGroup.columnWidth = 114;
            this._tileListGroup.rowHeight = 46;
            this._tileListGroup.horizontalGap = 9;
            this._tileListGroup.verticalGap = 6;
            this._tileListGroup.setStyle("cellRenderer", ArenaCrossGroupCellRenderer2);
            this.addChild(this._tileListGroup);
            ObjCreate.createBg(22, 500, 240, 2, this, "SplitLine");
            this._myBattle = ObjCreate.createGButton(Language.getString(44281), 30, 509, 70, 26, this);
            this._battleRule = ObjCreate.createGButton(Language.getString(44282), 66, 509, 70, 26, this);
            this._battlePrize = ObjCreate.createGButton(Language.getString(44283), 161, 509, 70, 26, this);
            this._matchPanel = new ArenaCrossGroupMatchPanel();
            this._matchPanel.x = 276;
            this._matchPanel.y = 38;
            this.addChild(this._matchPanel);
            this._myServer.addEventListener(flash.events.MouseEvent.CLICK, this.onClickMyServer);
            this._tileListGroup.addEventListener(flash.events.Event.CHANGE, this.onGroupChange);
            this._battleRule.addEventListener(flash.events.MouseEvent.CLICK, this.onClickBattleRule);
            this._battlePrize.addEventListener(flash.events.MouseEvent.CLICK, this.onClickBattlePrize);
            this._myBattle.addEventListener(flash.events.MouseEvent.CLICK, this.onClickMyBattle);
            this.updateGroupList();
            var loc1=Cache.instance.arenaCross.arenaCrossInfo;
            if (loc1 && loc1.myProcess >= loc1.process) 
            {
                loc2 = loc1.groupId;
                if (this._tileListGroup.dataProvider.length >= loc2) 
                {
                    this._tileListGroup.selectedIndex = (loc2 - 1);
                    this.onGroupChange();
                }
            }
            return;
        }

        /* internal  */onClickMyServer(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._myServer.selected = true;
            this.selectGroupId = 0;
            this._tileListGroup.selectedIndex = -1;
            return;
        }

        /* internal  */onGroupChange(arg1: Object /* flash.events.Event */=null): void
        {
            this._myServer.selected = false;
            if (this._tileListGroup.selectedItem) 
            {
                this.selectGroupId = (this._tileListGroup.selectedItem as ArenaCrossGroupIdData).groupId;
            }
            return;
        }

        /* internal  */onClickBattleRule(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.KingWarRuleDescToTabBar, 1));
            return;
        }

        /* internal  */onClickBattlePrize(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ShowKingWarModule));
            return;
        }

        /* internal  */onClickMyBattle(arg1: Object /* flash.events.MouseEvent */): void
        {
            GameManager.instance.popupView(ArenaCrossMyBattlesWindow.instance);
            return;
        }

        public updateGroupList(): void
        {
            var loc4=null;
            var loc1=new Array<any>();
            var loc2=0;
            if (Cache.instance.arenaCross.arenaCrossInfo && Cache.instance.arenaCross.arenaCrossInfo.myProcess >= Cache.instance.arenaCross.arenaCrossInfo.process) 
            {
                loc2 = Cache.instance.arenaCross.arenaCrossInfo.groupId;
            }
            var loc3=1;
            while (loc3 <= 16) 
            {
                loc4 = new ArenaCrossGroupIdData(loc3, loc2);
                loc1.push(loc4);
                ++loc3;
            }
            this._tileListGroup.dataProvider = new DataProvider(loc1);
            return;
        }

        protected set selectGroupId(arg1: int)
        {
            this._selectGroupId = arg1;
            this._matchPanel.groupId = arg1;
            return;
        }

        public updateTopList(arg1: SArenaCrossToplists): void
        {
            this._matchPanel.updateTopList(arg1);
            return;
        }

        public updateGroupBattles(arg1: SArenaCrossGroupBattles): void
        {
            this._matchPanel.updateGroupBattles(arg1);
            return;
        }

        public udpateMyBattles(arg1: SArenaCrossBattleRecords): void
        {
            this._matchPanel.udpateMyBattles(arg1);
            return;
        }

        public updateGroupBattleEnd(arg1: SArenaCrossGroupBattleEnd): void
        {
            this._matchPanel.updateGroupBattleEnd(arg1);
            return;
        }

        /* internal */ /* var */_selectGroupId: int=0;

        /* internal */ /* var */_myServer: ArenaCrossGroupMyServer;

        /* internal */ /* var */_tileListGroup: GTileList;

        /* internal */ /* var */_line: ScaleBitmap;

        /* internal */ /* var */_battleRule: GButton;

        /* internal */ /* var */_battlePrize: GButton;

        /* internal */ /* var */_myBattle: GButton;

        /* internal */ /* var */_matchPanel: ArenaCrossGroupMatchPanel;
    }
